package com.zj.imageloader;

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    //    private final String url = "http://jakewharton.github.io/butterknife/static/logo.png";
    private final String url =
            "http://www.cnplugins.com/uploads/crximage/201503/www.cnplugins.com_jjjfbaapeohdiokaolpoeelnccpdhofg_1.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ImageView ivImage = (ImageView) findViewById(R.id.iv_image);

        final ImageLoader imageLoader = new ImageLoader();
        new Thread(new Runnable() {
            @Override
            public void run() {
                final Bitmap bitmap = imageLoader.loadImage(url);
                if (bitmap != null) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ivImage.setImageBitmap(bitmap);
                        }
                    });
                }
            }
        }).start();
    }
}
